package com.hy.web;


import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hy.domain.About;
import com.hy.domain.Cases;
import com.hy.domain.Flow;
import com.hy.domain.Hotel;
import com.hy.domain.Poster;
import com.hy.domain.Service;

@Controller
public class HomeController {

	@RequestMapping({"/", "default", "index"})
	public String index(Model model){
		List<About> abouts = About.findAboutEntries(0, 1);
		if(abouts.size() > 0){
			model.addAttribute("about", abouts.get(0));
		}
		List<Hotel> hotels = Hotel.getReverseHotel(0, 8);
		List<Cases> cases = Cases.findCasesEntries((int)Cases.countCaseses() - 4, 4);
		Collections.reverse(cases);
		List<Service> services = Service.findServiceEntries((int)Service.countServices() - 3, 3);
		List<Poster> posters = Poster.findAllPosters();
		
		model.addAttribute("hotels", hotels);
		model.addAttribute("cases", cases);
		model.addAttribute("services", services);
		model.addAttribute("posters", posters);
		return "home";
	}
	
	@RequestMapping("about")
	public String about(Model model){
		List<About> list = About.findAboutEntries(0, 1);
		if (list.size() > 0) {
			 model.addAttribute("about", list.get(0));
		}
		return "about";
	}
	
	@RequestMapping("hzlc")
	public String hzlc(Model model){
		List<Flow> list = Flow.findFlowEntries(0, 1);
		if(list.size() > 0){
			model.addAttribute("flow", list.get(0));
		}
		return "hzlc";
	}
	
	@RequestMapping("lxwm")
	public String lxwm(Model model){
		List<Flow> list = Flow.findFlowEntries(0, 1);
		if (list.size() > 0) {
			model.addAttribute("flow", list.get(0));
		}
		return "lxwm";
	}
	
	@RequestMapping("admin")
	public String admin(){
		return "index";
	}
	
	
}
